#ifndef UDP_THREAD_H
#define UDP_THREAD_H
#include<windows.h>
#include "main.h"

#define LOACL_ID_FLAG  (0x5A4B)
#define MASTER_ID_FLAG (0x3B4D)
DWORD WINAPI can_rx(LPVOID pParam);

#pragma pack(1)


struct udp_general_packet
{
  unsigned char protocol_name[8];
  unsigned short len;
  unsigned short len_inverse;
  unsigned short src;
  unsigned short dst;
  unsigned short cmd_count;
  unsigned short cmd_re_count;
  unsigned short cmd_code;
  unsigned char ack;
  unsigned char is_ack;
  unsigned char data[8];
  unsigned int check_sum;
};

struct udp_4bytes_data_cmd_packet
{
  unsigned char protocol_name[8];
  unsigned short len;
  unsigned short len_inverse;
  unsigned short src;
  unsigned short dst;
  unsigned short cmd_count;
  unsigned short cmd_re_count;
  unsigned short cmd_code;
  unsigned char ack;
  unsigned char is_ack;
  unsigned char data[4];
  unsigned int check_sum;
};


struct udp_8bytes_data_cmd_packet
{
  unsigned char protocol_name[8];
  unsigned short len;
  unsigned short len_inverse;
  unsigned short src;
  unsigned short dst;
  unsigned short cmd_count;
  unsigned short cmd_re_count;
  unsigned short cmd_code;
  unsigned char ack;
  unsigned char is_ack;
  unsigned char data[8];
  unsigned int check_sum;
};


struct slave_adaptor_parm_set_cmd_data
{
  unsigned int slave_mount_flag;
  struct laser_adaptor_paramter slave_adaptor_parm;
};


struct udp_slave_parm_set_packet
{
  unsigned char protocol_name[8];
  unsigned short len;
  unsigned short len_inverse;
  unsigned short src;
  unsigned short dst;
  unsigned short cmd_count;
  unsigned short cmd_re_count;
  unsigned short cmd_code;
  unsigned char ack;
  unsigned char is_ack;
  struct slave_adaptor_parm_set_cmd_data data;
  unsigned int check_sum;
};

struct udp_master_parm_set_packet
{
  unsigned char protocol_name[8];
  unsigned short len;
  unsigned short len_inverse;
  unsigned short src;
  unsigned short dst;
  unsigned short cmd_count;
  unsigned short cmd_re_count;
  unsigned short cmd_code;
  unsigned char ack;
  unsigned char is_ack;
  struct master_conctrller_adaptor_paramter data;
  unsigned int check_sum;
};








struct eth_power_set_cmd_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char cd;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;

};

struct eth_power_output_cmd_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char output_operate_flag;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;

};


struct eth_reset_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;

};

struct eth_fight_pre_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char pre_operate;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;

};


struct eth_withdraw_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;

};


struct eth_ada_parm_set_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  struct adaptor_paramter_summary ada_parm;
  unsigned int  check_sum;
  unsigned int  end;

};

struct eth_ada_store_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char store_flag;
  unsigned int  check_sum;
  unsigned int  end;

};

struct eth_ada_parm_query_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned int  check_sum;
  unsigned int  end;

};


struct eth_operate_parm_query_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned int  check_sum;
  unsigned int  end;

};

struct eth_debug_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char operate_flag;
  unsigned int  check_sum;
  unsigned int  end;
};

struct eth_week_light_mode_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned char operate_flag;
  unsigned char enable_config;
  unsigned int  check_sum;
  unsigned int  end;
};




struct eth_heart_packet
{
  unsigned int start;
  unsigned char co_ver;
  unsigned short len;
  unsigned char src;
  unsigned char dst;
  unsigned long long time_stamp;
  unsigned short cmd_info;
  unsigned int  check_sum;
  unsigned int  end;

};

#pragma pack()


DWORD WINAPI udp_process(LPVOID pParam);
void udp_fight_parm_set(void);
void udp_reset(void);
void udp_fight_pre(void);
void udp_withdraw(void);
void udp_slave_adaptor_set(void);
void udp_adaptor_store(void);
void udp_adaptor_query(void);
void udp_operate_query(void);

void udp_adaptor_init(void);
void udp_enter_debug(void);
void udp_exit_debug(void);
void udp_cold_standy_pre(void);
void udp_hot_standy_pre(void);
void udp_output_strong_light(void);
void udp_stop_light(void);
void udp_output_red_light(void);
void udp_output_week_1_light(void);
void udp_output_week_2_light(void);
void udp_enter_week_light_mode(void);
void udp_exit_week_light_mode(void);
void udp_connect(void);
void send_4bytes_data_cmd(unsigned short cmd_code , unsigned char ack , unsigned char is_ack , unsigned char* data);
void udp_disconnect(void);
void udp_upload_start(void);
void udp_slave_adaptor_store(void);
void udp_slave_adaptor_init(void);
void udp_master_adaptor_set(void);
void udp_master_adaptor_store(void);
void udp_master_adaptor_init(void);



DWORD WINAPI udp_heart(LPVOID pParam);
void udp_alive();


extern unsigned char udp_stop;


#endif // UDP_THREAD_H
